<template>
    <view class="content">
        <!-- 搜索栏 -->
        <u-sticky>
            <view class="section slogan">
                <view class="search-box">
                    <u-search placeholder="想看的文章标题或类别" clearabled v-model="SearchName" @clear="POST_ArtSearch()"
                        @clickIcon="POST_ArtSearch()" @search="POST_ArtSearch()" @custom="POST_ArtSearch()">
                    </u-search>
                </view>
            </view>
            <u-line dashed style="margin: 20rpx 0"></u-line>
        </u-sticky>
        <!-- 标签云栏 -->
        <u-gap height="15" bgColor="#f2f5f9"></u-gap>
        <view class="section section-bord">
            <view class="se-title">文章类别</view>
            <u-line dashed style="margin: 20rpx 0"></u-line>
            <view class="tags-box">
                <view class="tags-item" :style="{'background-color':item.color}" v-for="item in tagsList"
                    :key="item.id">
                    {{item.name}}
                </view>
            </view>
        </view>
        <u-gap height="15" bgColor="#f2f5f9"></u-gap>
        <!-- 搜索的内容 -->
        <view class="section-list">
            <u-empty v-if="!ArtSearch.length" mode="data">
            </u-empty>
            <template v-else>
                <view class="section-item" v-for="item in ArtSearch" :key="item.Id" @click="goPostDetail(item)">
                    <view class="list-desc">
                        <view class="desc-title">
                            <view class="isTop">
                                {{item.title}}
                            </view>
                        </view>
                        <view class="desc-com">
                            简介：{{item.summary}}
                        </view>
                        <view class="">类别：{{item.cate_name}}</view>
                    </view>
                </view>
                <u-divider text="END"></u-divider>
            </template>
        </view>
    </view>
</template>

<script>
    import {
        dirTagsList,
        ArtSearch
    } from '@/api/cates/index.js';

    export default {
        data() {
            return {
                iconStyle: {
                    fontSize: '28rpx',
                    color: '#dd524d'
                },
                scrollTop: 0,
                title: "LF'blog",
                tagsList: [],
                list1: [],
                ArtSearch: [],
                SearchName: ''
            }
        },
        onShow() {
            this.getTagsList()
        },
        onPageScroll(e) {
            this.scrollTop = e.scrollTop;
        },
        methods: {
            randomColor() {
                let r = Math.floor(Math.random() * 255);
                let g = Math.floor(Math.random() * 255);
                let b = Math.floor(Math.random() * 255);
                console.log('rgba(' + r + ',' + g + ',' + b + ',0.8)')
                return 'rgba(' + r + ',' + g + ',' + b + ',0.8)';
            },
            getTagsList() {
                dirTagsList().then(res => {
                    for (const argument of res.data.data) {
                        argument.color = this.randomColor()
                    }
                    this.tagsList = res.data.data
                    console.log(res)
                }).catch(err => {
                    console.log(err)
                })
            },
            POST_ArtSearch() {
                if (uni.getStorageSync('token')) {
                    var data = {
                        SearchName: this.SearchName
                    }
                    ArtSearch(data).then(res => {
                        this.ArtSearch = res.data.items
                        console.log(this.ArtSearch)
                    });
                    uni.stopPullDownRefresh()
                } else {
                    uni.showToast({
                        icon: 'none',
                        position: 'bottom',
                        title: '请登录'
                    });
                    setTimeout(() => {
                        uni.navigateTo({
                            url: '/pages/user/login/login'
                        })
                    }, 1000)
                }
            },
            goPostDetail(row) {
                uni.navigateTo({
                    url: '/pages/index/articleInfo/articleInfo?Id=' + row.Id
                });
            }
        }
    }
</script>

<style lang="scss" scoped>
    .content {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding-top: 20rpx;
    }

    .se-title {
        margin-bottom: 20rpx;
        border-left: 10rpx solid #d81e06;
        border-radius: 5rpx;
        padding-left: 10rpx;
        font-weight: bold;
    }

    .section {
        width: 700rpx;
        margin: 0 rpx auto;
        box-sizing: border-box;
        background-color: #fff;
        border-radius: 10rpx;

        &-bord {
            padding: 20rpx;

            .tags-box {
                display: flex;
                justify-content: center;
                flex-wrap: wrap;
                padding: 20px 0;

                .tags-item {
                    padding: 5px;
                    border-radius: 5px;
                    color: #0c0c0c;
                    text-shadow: 0rpx 0rpx 15rpx #fff;
                    font-size: 26rpx;
                    font-family: 'monaco', 'Consolas', "Liberation Mono", Courier, monospace;
                    margin: 3px;

                }
            }
        }
    }

    .slogan {
        padding: 30rpx;
        position: relative;
        font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
        color: #908f8f;

        &:before {
            content: '';
            position: absolute;
            left: 0rpx;
            top: 0rpx;
            width: 10rpx;
            height: 100%;
            border-bottom-left-radius: 10rpx;
            border-top-left-radius: 10rpx;
            background-color: #d81e06;

        }

        .search-box {
            margin-top: 15px;
        }
    }

    .section {
        width: 700rpx;
        margin: 0rpx auto;
        box-sizing: border-box;
        background-color: #fff;
        border-radius: 10rpx;

        &-quick {
            height: 250rpx;
            padding: 20rpx;

            .quick-top {
                padding-bottom: 20rpx;

                .quick-logo {
                    width: 80rpx;
                    height: 80rpx;
                    margin-bottom: 8rpx;
                }

                .grid-text {
                    font-size: 22rpx;
                    color: #555454;
                    text-align: center;
                }
            }

            .quick-bottom {
                display: flex;
                justify-content: center;
                align-content: center;

                .bot-right {
                    width: 100%;
                    padding-top: 10rpx;
                }
            }

        }

        &-list {
            .section-item {
                width: 700rpx;
                margin-bottom: 20rpx;
                box-sizing: border-box;
                background-color: #fff;
                border-radius: 10rpx;
                height: 200rpx;
                padding: 20rpx;
                display: flex;
                justify-content: flex-start;
                align-content: center;

                .list-logo {
                    width: 150rpx;
                    height: 150rpx;
                    overflow: hidden;
                    display: flex;
                    justify-content: center;
                    align-content: center;
                    border-radius: 50%;
                    box-sizing: 0rpx 0rpx 10rpx #636363;
                    border: 1rpx solid #eee;
                }

                .list-desc {
                    width: calc(100% - 150rpx);
                    padding-left: 20rpx;
                    font-family: 'monaco', 'Consolas', "Liberation Mono", Courier, monospace;

                    .desc-title {
                        font-weight: bold;
                        font-size: 25px;
                        padding-bottom: 14rpx;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        white-space: nowrap;


                        .isTop {
                            color: #fff;
                            text-shadow: 0rpx 5rpx 15rpx #dec1c1;
                            background-color: #d81e06;
                            padding: 5rpx 8rpx;
                            border-radius: 8rpx;
                            margin-right: 5rpx;
                            font-size: 22rpx;
                        }
                    }

                    .desc-com {
                        font-size: 15px;
                        line-height: 30rpx;
                        text-indent: 0.5rem;
                        height: 60rpx;
                        overflow: hidden;
                        display: -webkit-box;
                        -webkit-box-orient: vertical;
                        -webkit-line-clamp: 2;
                        color: crimson;
                    }

                    .desc-time {
                        padding-top: 15rpx;
                        color: #999;
                        font-size: 12px;
                        display: flex;
                        justify-content: flex-start;
                        align-content: center;

                        .time {
                            padding-left: 8rpx;
                        }
                    }
                }

            }
        }
    }
</style>
